//
//  SimpleDownLoadManager.h
//  Portal
//
//  Created by JingXing Wu on 12-3-15.
//  Copyright (c) 2012年 GuangZhouXuanWu. All rights reserved.
//

#import <Foundation/Foundation.h>

#import "XMSSimpleDownloadHelper.h"

#import "XMSDataOperationManager.h"

#define OBSERVER_SDM_DOWNLOAD_FINISH        @"OBSERVER_SDM_DOWNLOAD_FINISH"

#define OBSERVER_SDM_DOWNLOAD_ERROR         @"OBSERVER_SDM_DOWNLOAD_ERROR"

@interface CSimpleDownloadTaskTag : NSObject

@property(nonatomic,readonly) NSString *URL;
@property(nonatomic,readonly) NSString *filePath;
@property(nonatomic,readonly) id attachment;

@end

@class XMSSimpleDownloadManager;

@protocol XMSSimpleDownloadManagerDelegate <NSObject>

@optional
- (void)simpleDownloadManager:(XMSSimpleDownloadManager *)sdm willStartDownload:(CSimpleDownloadTaskTag *)tag;

- (void)simpleDownloadManager:(XMSSimpleDownloadManager *)sdm tag:(CSimpleDownloadTaskTag *)tag error:(NSError*)error;

- (void)simpleDownloadManager:(XMSSimpleDownloadManager *)sdm didStartDownload:(CSimpleDownloadTaskTag *)tag;

- (void)simpleDownloadManager:(XMSSimpleDownloadManager *)sdm cancelRequest:(CSimpleDownloadTaskTag *)tag;

- (void)simpleDownloadManager:(XMSSimpleDownloadManager *)sdm tag:(CSimpleDownloadTaskTag *)tag fileTotalSize:(long long)totalSize;

- (void)simpleDownloadManager:(XMSSimpleDownloadManager *)sdm tag:(CSimpleDownloadTaskTag *)tag fileTotalSize:(long long)totalSize fileWrittenSize:(long long)writtenSize;

- (NSString*)simpleDownloadManager:(XMSSimpleDownloadManager*)helper needTransferURL:(NSString*)URL;

@required
- (void)simpleDownloadManager:(XMSSimpleDownloadManager *)sdm finishedDownload:(CSimpleDownloadTaskTag *)tag;

@end

@interface XMSSimpleDownloadManager : XMSDataOperationManager

- (id)initWithDelegate:(id<XMSSimpleDownloadManagerDelegate>)delegate;

- (void)initDownloadQueue:(id <XMSSimpleDownloadManagerDelegate>)delegate;

- (void)releaseDownloadQueue;

- (void)addDownloadTask:(NSString *)szUrl path:(NSString *)szFilepath attachment:(id)attachment;

- (void)cancelAllDownloadTask;

- (void)terminateAllDownloadTask;

- (BOOL)isContainDownloadURL:(NSString *)szUrl;

@end

@interface XMSSimpleDownloadManager (TransferURL)

/**
*  对URL进行转换处理，回调中的“simpleDownloadManager:needTransferURL:”优先级比此方法高，若回调方法返回的URL与传入的相同，还是会调用此方法
*
*  @param transferURL 需要处理URL的block
*/
+(void)operateNeedTransferURLBlock:(NSString*(^)(NSString *URL))transferURL;

@end
